const express = require('express');
const router = express.Router();
const data = [];
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        brandCode: `brandCode${i}`,
        brandName: `brandName${i}`,
        dealerCode: `dealerCode${i}`,
        dealerName: `dealerName${i}`,
        code: `code${i}`,
        orderPlanYear: i,
        orderPlanMonth: i,
        // eslint-disable-next-line no-nested-ternary
        status: (i % 5 === 0 ? 1 : (i % 2 === 0 ? 2 : -1)),
        n1OrderVarietySum: i,
        n1OrderPlanQty: i,
        currency: i,
        totalFee: i,
        createTime: '2019-08-28 18:34:59',
        rowVersion: 'A11111111',
        options: ['update', 'submit', 'abandon', 'approve']
    });
router.get('/forCurrentUser', (req, res) => {
    const {pageIndex, pageSize, brandCode} = req.query;
    const result = brandCode === null || brandCode === undefined ? data : data.filter(item => item.brandCode.indexOf(brandCode) >= 0);
    res.json({
        message: '',
        payload: {
            // eslint-disable-next-line radix
            content: result.slice(parseInt(pageIndex) * parseInt(pageSize), (parseInt(pageIndex) + 1) * parseInt(pageSize)),
            totalElements: result.length,
        }
    });
});

router.put('/:id', (req, res) => {
    res.json({
        message: '编辑成功'
    });
});

router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});

router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});

router.put('/:id/submit', (req, res) => {
    res.json({
        message: '提交成功'
    });
});

router.put('/:id/pass', (req, res) => {
    res.json({
        message: '审核通过'
    });
});

router.put('/:id/reject', (req, res) => {
    res.json({
        message: '驳回成功'
    });
});

router.post('/query', (req, res) => {
    res.json({
        message: 'success',
        payload: {
            content: [{
                id: '1',
                partId: '1',
                partCode: 'code1',
                partName: '配件1配件1',
                productCategoryCode: '产品分类1',
                minPackSize: 5,
                unit: '个',
                price: 10,
                n1Quantity: 1,
                n2Quantity: 2,
                n3Quantity: 3,
                isChange: true
            }, {
                id: '1',
                partId: '2',
                partCode: 'code2',
                partName: '配件2配件2',
                productCategoryCode: '产品分类2',
                minPackSize: 6,
                unit: '个',
                price: 5,
                n1Quantity: 5,
                n2Quantity: 2,
                n3Quantity: 0,
                isChange: true
            }]
        }
    });
});

router.get('/forPartSaleOrder', (req, res) => {
    const contentforPartOrderPi = [];
    for(let i = 1; i < 51; i++)
        contentforPartOrderPi.push({
            id: `${i}`,
            code: `XQ2019082700-${i}`,
            dealerId: 'dealerId111',
            dealerCode: `dealerCode${i}`,
            dealerName: `dealerName${i}`,
            orderPlanYear: 2019,
            orderPlanMonth: 10,
            n1OrderVarietySum: 20,
            n1OrderPlanQty: 30
        });
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: contentforPartOrderPi,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

router.get('/forPartSaleOrder/:id', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: '1',
            code: 'XS2019082700-1',
            details: [
                {
                    partId: '1',
                    partCode: 'partCode1',
                    partName: 'partName1',
                    n1Quantity: 3,
                    stockQuantity: 4,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1,
                    partSaleOrderTypeId: '1',
                    transportType: 1
                },
                {
                    partId: '2',
                    partCode: 'partCode2',
                    partName: 'partName2',
                    n1Quantity: 3,
                    stockQuantity: 4,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1,
                    partSaleOrderTypeId: '2',
                    transportType: 1
                },
                {
                    partId: '3',
                    partCode: 'partCode3',
                    partName: 'partName3',
                    n1Quantity: 3,
                    stockQuantity: 4,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1,
                    partSaleOrderTypeId: '2',
                    transportType: 1
                }
            ]
        }
    });
});
router.get('/export/forCurrentUser', (req, res) => {
    res.json({
        message: 'success',
        payload: 'Mock导出'
    });
});

router.get('/:id', (req, res) => {
    const {id} = req.params;
    res.json(
        {
            message: 'string',
            payload: {
                id: '1',
                code: `code${id}`,
                dealerId: `dealerId${id}`,
                dealerCode: `dealerCode${id}`,
                dealerName: `dealerName${id}`,
                brandId: `brandId${id}`,
                brandCode: `brandCode${id}`,
                brandName: `brandName${id}`,
                country: `brandName${id}`,
                orderPlanYear: 2,
                orderPlanMonth: 3,
                n1OrderVarietySum: 334,
                n1OrderPlanQty: 342,
                currency: 2,
                totalFee: 4234,
                createTime: '2019-08-28 18:34:59',
                remark: 'remark2222',
                rowVersion: 'A11111111',
                branchCode: 'QR',
                branchName: '奇瑞',
                status: 1,
                createName: '创建人',
                modifyName: '修改人',
                modifyTime: '2019-08-31 18:34:59',
                submitterName: '提交人',
                submitTime: '2019-08-29 18:34:59',
                confirmorName: '审核人',
                confirmTime: '2019-08-30 18:34:59',
                abandonerName: '作废人',
                abandonTime: '2019-08-31 18:34:59',
                approvedContent: '通过',
                options: ['update', 'submit', 'abandon', 'approve'],
                details: [{
                    id: '1',
                    partId: '1',
                    partCode: 'code1',
                    partName: '配件1配件1',
                    description: 'yinwenmiaoshu1',
                    productCategoryCode: '产品分类1',
                    minPackSize: 1,
                    unit: '个',
                    price: 10,
                    estimatedPrice: 50,
                    n1Quantity: 1,
                    n2Quantity: 2,
                    n3Quantity: 3,
                    partOutQuantity: 6,
                    stockQuantity: 5
                }, {
                    id: '2',
                    partId: '2',
                    partCode: 'code2',
                    partName: '配件1配件1',
                    description: 'yinwenmiaoshu2',
                    productCategoryCode: '产品分类2',
                    minPackSize: 1,
                    unit: '个',
                    price: 5,
                    estimatedPrice: 20,
                    n1Quantity: 5,
                    n2Quantity: 2,
                    n3Quantity: 1,
                    partOutQuantity: 10,
                    stockQuantity: 4
                }]
            }
        }
    );
});

router.get('/forHistory/forCurrentUser', (req, res) => {
    const content = [];
    for(let i = 1; i < 51; i++)
        content.push({
            id: `${i}`,
            dealerCode: `dealerCode${i}`,
            dealerName: `dealerName${i}`,
            code: `code${i}`,
            planYearmonth: '2019-09',
            createTime: '2019-11-16T06:42:33.259Z',
            status: 16421004,
            rowVersion: 'rowVersion'
        });
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

router.get('/:id/forHistory', (req, res) => {
    const {id} = req.params;
    res.json(
        {
            message: 'string',
            payload: {
                id: '1',
                code: `code${id}`,
                dealerCode: `dealerCode${id}`,
                country: `brandName${id}`,
                createTime: '2019-08-28 18:34:59',
                remark: 'remark2222',
                rowVersion: 'A11111111',
                status: 16421002,
                planYearmonth: '2019-11',
                partOrderPlanHisDetails: [
                    {
                        partId: '1',
                        partCode: 'code1',
                        partName: '配件1',
                        partEngName: 'part one',
                        productCategoryCode: '产品分类1',
                        minPackSize: 1,
                        orderQuantity: 1200,
                        remark: 'remark',
                    },
                    {
                        partId: '2',
                        partCode: 'code2',
                        partName: '配件2',
                        partEngName: 'part two',
                        productCategoryCode: '产品分类2',
                        minPackSize: 2,
                        orderQuantity: 1200,
                        remark: 'remark',
                    }],
                partOrderPlanHisProcessDetails: [
                    {
                        processer: 'processer1',
                        processStatus: 16421002,
                        processComment: 'processComment1',
                        processDate: '2019-08-28 18:34:59'
                    },
                    {
                        processer: 'processer2',
                        processStatus: 16421003,
                        processComment: 'processComment2',
                        processDate: '2019-08-28 18:34:59'
                    }
                ]
            }
        }
    );
});

module.exports = router;
